import {getUser} from "@/api/request";

const state = {
    userData: {},
    menuData: [],
    buttonData: []
};

const mutations = {
    CHANGE_MENU(state, payload) {
        state.menuData = payload;
    },
    CHANGE_USERDATA(state, payload) {
        state.userData = payload;
    },
    CHANGE_BUTTONData(state, payload) {
        state.buttonData = payload;
    }
};

// 异步操作
const actions = {
    // 获取用户信息
    async getUserInfo({commit}, payload) {
        const {data} = await getUser();
        commit("CHANGE_BUTTONData", data.button);
        commit("CHANGE_MENU", data.menu);
        commit("CHANGE_USERDATA", data.userInfo);
    }
}
const userStore = {
    // namespaced 开启命名空间,作用是为了方式不同的模块命名冲突;
    namespaced: true,
    state,
    mutations,
    actions
};
export default userStore;